package vistas;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
//import utilitarios.ConstantesDeGUI;
//import juego.*;
import controladores.ControladorCompra;
//import controladores.ControladorCargaJugadores;


public class EleccionComponente extends JDialog {

	private static final long serialVersionUID = 1L;
	private ControladorCompra controlCompra;
	private JPanel panel;
	private JLabel anuncio;
	private JLabel etiqueta1;
	private JLabel etiqueta2;
	private JLabel etiqueta3;
	private JRadioButton seleccion1;
	private JRadioButton seleccion2;
	private JRadioButton seleccion3;
	private JButton enviarEleccion;
	
	/**
	 * Instancia una nueva EleccionTipoDeContrincantes.
	 * 
	 * @param cargaJugadores the carga jugadores
	 */
	public EleccionComponente(ControladorCompra controlCompra){
		super();
		this.controlCompra = controlCompra;
		initsComponents();
	}

	/**
	 * Asigna escuchadores.
	 */
	private void asignarEscuchadores() {
		this.enviarEleccion.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent event){
				if(seleccion1.isSelected()){
					controlCompra.comprar("motorEspecial");
					ocultar();
				}else{
					if(seleccion2.isSelected()){
						controlCompra.comprar("carburadorEspecial");
						ocultar();
					}else{
						if(seleccion3.isSelected()){
							controlCompra.comprar("cajaEspecial");
							ocultar();
     					}
					}
				}
			}
		});
	}
	
	/**
	 * Oculta el formulario.
	 */
	private void ocultar(){
		this.setVisible(false);
	}
	
	/**
	 * Muestra el formulario.
	 */
	public void mostrar(){
		this.setVisible(true);
	}

	/**
	 * Inicializa los componentes.
	 */
	private void initsComponents() {
		this.setSize(450,400);
    	this.setLocation(350,150);
    	this.setResizable(true);
    	this.setTitle("Taller");        
    	// si el usuario opta por cerra el cuadro de eleccion de jugadores no se aborta la aplicacion
    	// solo se cierra y se muestra la pantalla principal.
    	this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    	GridBagConstraints constraints = new GridBagConstraints();
    	this.panel = new JPanel();
    	panel.setLayout(new GridBagLayout());
         
        this.anuncio = new JLabel("Seleccione el tipo de COMPONENTE");
        this.etiqueta1 = new JLabel("Motor Super-Precio:11000.0 $");
        this.etiqueta2 = new JLabel("Motor Medio-Precio:9000.0 $");
        this.etiqueta3 = new JLabel("Caja Especial-Precio:1800.0 $");
        this.seleccion1 = new JRadioButton();
        this.seleccion1.setSelected(true);
        this.seleccion1.addMouseListener(new MouseAdapter(){
        	public void mouseClicked(MouseEvent event){
				if(seleccion1.isSelected()){
					seleccion2.setSelected(false);
					seleccion3.setSelected(false);
				}
        }
        });
        this.seleccion2 = new JRadioButton();
        this.seleccion2.addMouseListener(new MouseAdapter(){
        	public void mouseClicked(MouseEvent event){
				if(seleccion2.isSelected()){
					seleccion1.setSelected(false);
					seleccion3.setSelected(false);
				}
        }
        });
        this.seleccion3 = new JRadioButton();
        this.seleccion3.addMouseListener(new MouseAdapter(){
        	public void mouseClicked(MouseEvent event){
				if(seleccion3.isSelected()){
					seleccion1.setSelected(false);
					seleccion2.setSelected(false);
				}
        }
        });
        this.enviarEleccion = new JButton("Enviar");
        constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.gridwidth = 1;
		constraints.gridheight = 1;
		constraints.weightx = 0.0;
		constraints.weighty = 1.0;
		constraints.anchor = GridBagConstraints.CENTER;
		constraints.fill = GridBagConstraints.HORIZONTAL;
        this.panel.add(anuncio, constraints);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridy = 1;
        this.panel.add(etiqueta1, constraints);
        constraints.gridy = 2;
        this.panel.add(etiqueta2, constraints);
        constraints.gridy = 3;
        this.panel.add(etiqueta3, constraints);
        constraints.gridx = 1;
        constraints.gridy = 1;
        this.panel.add(seleccion1, constraints);

        constraints.gridx = 1;
        constraints.gridy = 2;
        this.panel.add(seleccion2, constraints);
        constraints.gridx = 1;
        constraints.gridy = 3;
        this.panel.add(seleccion3, constraints);
        constraints.gridx = 1;
        constraints.gridy = 4;
        this.panel.add(enviarEleccion, constraints);
        asignarEscuchadores();
        this.add(this.panel);
	}
	
}
